package com.ruoyi.web.controller.mongo;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mongo.comprehensive.SeniorChinToEng;
import com.ruoyi.mongo.service.MongoConstants;
import com.ruoyi.mongo.senior.entity.Senior;
import com.ruoyi.mongo.senior.entity.SeniorRecord;
import com.ruoyi.mongo.senior.service.SeniorInterface;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/senior")
public class SeniorController {

    private final SeniorInterface seniorInterface;

    public SeniorController(SeniorInterface seniorInterface) {
        this.seniorInterface = seniorInterface;
    }

    @GetMapping("/list")
    public AjaxResult getExamList(@RequestParam(required = false) int group) {
        List<Senior> list = seniorInterface.selectListByGroup(group);
        return AjaxResult.success(list);
    }

    @GetMapping("/practice")
    public AjaxResult getExamTestDetail(@RequestParam(required = false) String practice) {
        List<SeniorRecord> list = seniorInterface.selectTestListByPractice(practice);
        return AjaxResult.success(list);
    }

    @GetMapping("/listOneMeaning")
    public AjaxResult getExamListOneMeaning(@RequestParam(required = false) int group) {
        List<Senior> list = seniorInterface.selectListOnlyOneMeaning(group);
        return AjaxResult.success(list);
    }

    @PostMapping("/dataOne")
    public AjaxResult putData(@RequestBody Senior entity){
        seniorInterface.saveData(entity);
        return AjaxResult.success();
    }

    //学习记录-保存
    @PostMapping("/dataList")
    public AjaxResult putDataList(@RequestBody List<Senior> seniorList){
        seniorInterface.saveData(seniorList);
        return AjaxResult.success();
    }

    //学习记录-查询
    @GetMapping("/study_detail")
    public AjaxResult getSeniorStudyDetail(@RequestParam(required = false) String practice) {
        List<SeniorRecord> list = seniorInterface.selectStudyDetailByPractice(practice);
        return AjaxResult.success(list);
    }

    //测试记录
    @PostMapping("/dataTestList")
    public AjaxResult putDataTestList(@RequestBody List<SeniorRecord> seniorList){
        seniorInterface.saveTestData(seniorList);
        return AjaxResult.success();
    }

    @PostMapping("/net")
    public AjaxResult putNetData(@RequestBody Senior entity){
        seniorInterface.insertNetDataByUser(entity);
        return AjaxResult.success();
    }

    /**
     * 汉译英记录-保存
     * 单个
     */
    @PostMapping("/chinToEngData")
    public AjaxResult putChinToEngData(@RequestBody SeniorChinToEng entity) {
        seniorInterface.saveWriteData(entity, MongoConstants.COLLECT_SENIOR_CHIN_TO_ENG);
        return AjaxResult.success(DateUtils.getLocalTime());
    }

    /**
     * 汉译英详情
     * 列表
     */
    @GetMapping("/writeDetailsList")
    public AjaxResult getWriteDetailsList(@RequestParam(required = false) String practice) {
        List<SeniorChinToEng> list = seniorInterface.selectWriteListByPractice(practice);
        return AjaxResult.success(list);
    }
}
